const  mongoose =require("mongoose");
const  mongooseConf=require("./dbConf");

let DB_URL = mongooseConf.host;
let DB_PORT = mongooseConf.port;
let DB_BASE = mongooseConf.database;
let db=`mongodb://${DB_URL}:${DB_PORT}/${DB_BASE}`;
// console.log(db);
// let db='mongodb://localhost:27017/studyMongo';
mongoose.connect(db,{ useNewUrlParser: true });

//链接数据库成功回调
mongoose.connection.on("connected",()=>{
    console.log("链接数据库成功");
})
//链接数据库失败回调
mongoose.connection.on("err",()=>{
    console.log("链接数据库失败");
})
//断开链接回调
mongoose.connection.on("disconnected",()=>{
    console.log("断开链接");
})

module.exports=mongoose;
